package com.xuetang9.t9.hotel.services.impl;

import com.xuetang9.t9.hotel.beans.RoomInfo;
import com.xuetang9.t9.hotel.mapper.IRoomInfoMapper;
import com.xuetang9.t9.hotel.mapper.condition.impl.RoomInfoCondition;
import com.xuetang9.t9.hotel.services.IRoomInfoService;
import com.xuetang9.t9.hotel.utils.PageBean;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomInfoServiceImpl implements IRoomInfoService {

    @Autowired
    private IRoomInfoMapper roomInfoMapper;

    @Override
    public boolean save(RoomInfo roomInfo) {
        return roomInfoMapper.insert(roomInfo) > 0;
    }

    @Override
    public boolean update(RoomInfo roomInfo) {
        return roomInfoMapper.update(roomInfo) > 0;
    }

    @Override
    public boolean remove(Integer roomId) {
        return roomInfoMapper.delete(roomId) > 0;
    }

    @Override
    public PageBean findByAll(RoomInfoCondition roomInfoCondition) {
        if(roomInfoCondition == null){
            roomInfoCondition = new RoomInfoCondition();
        }
        PageBean pageBean = new PageBean();
        pageBean.ok(roomInfoMapper.selectByAll(roomInfoCondition));
        pageBean.setCount(findByCount(roomInfoCondition));
        return pageBean;
    }

    @Override
    public Long findByCount(RoomInfoCondition roomInfoCondition) {
        return roomInfoMapper.selectByCount(roomInfoCondition);
    }

    @Override
    public int pageCount(int pageSize) {
        return 0;
    }

    @Override
    public boolean batchByStart(List<Integer> rooms, Integer startId) {
        return roomInfoMapper.updateByStart(rooms,startId) > 0;
    }
}
